// pages/my/my.js
// 我的页
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    myHeadImg: '/assets/imgs/myHead.png',
    myMore: '/assets/icons/more.png',
    userInfo: null,
    showRoleNav: false,
  },
  // 修改密码
  changePassWord: function() {
    wx.navigateTo({
      url: '/pages/modifyPassWord/modifyPassWord',
    })
  },
  // 退出登录
  signOut: function() {
    wx.showModal({
      title: '确认要退出登录？',
      content: '',
      success(res) {
        if (res.confirm) {
          console.log('确定')
          userInfo: null;
          wx.redirectTo({
            url: '/pages/signIn/signIn',
          })
        } else if (res.cancel) {
          console.log('取消')
        }
      }
    })
  },
  openProjectHomePage: function() {
    // 跳转到项目主页
    wx.redirectTo({
      url: '/pages/projectHomePage/projectHomePage',
    })
  },
  openRoleSigninPage: function() {
    // 打开签到页
    wx.redirectTo({
      url: '/pages/roleSigninPage/roleSigninPage',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let that = this
    let userInfo = app.globalData.userInfo
    if (userInfo == null) {
      wx.redirectTo({
        url: '/pages/signIn/signIn',
      })
    } else {
      this.setData({
        userInfo: userInfo
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },
  onShow: function() {
    // 判断：基层和中高层账号显示tabbar，网红/摄影师/化妆师隐藏tabbar
    let level = wx.getStorageSync('level')
    if (level > 2) {
      wx.hideTabBar()
      this.setData({
        showRoleNav: true
      })
    } else if(level<=2){
      wx.showTabBar()
      this.setData({
        showRoleNav: false
      })
    }
  }
})